package com.ruoyi.common.utils.translate;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.utils.translate.TransApi;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Main {

    // 在平台申请的APP_ID 详见 http://api.fanyi.baidu.com/api/trans/product/desktop?req=developer
    private static final String APP_ID = "20231204001900524";
    private static final String SECURITY_KEY = "OnaTbvenGtOK0NawlfG2";

    public static void main(String[] args) {
        TransApi api = new TransApi(APP_ID,SECURITY_KEY);
        TranslateUtil util = new TranslateUtil();

        try {

            String query = "这是一段中文\n这是一段英文";
            String en = api.getTransResult(query, api.ZH_LANG, "en");

            List<String> conversion = util.batchConversion(en);
            System.out.println(conversion);
            // 提取 "trans_result" 数组中第一个元素的 "dst" 值
//            String dstValue = jsonNode.get("trans_result").get(0).get("dst").asText();
//            JsonNode trans_result = jsonNode.get("trans_result");
//
//            System.out.println(trans_result);
        } catch (Exception e) {
            System.out.println("Error occurred while parsing JSON: " + e);
            e.printStackTrace();
        }
//        System.out.println(en);
//        System.out.println(en.indexOf("dst"));
    }

}
